/*
* @Author: dengjiayao
* @Date:   2017-07-12 09:18:26
* @Last Modified by:   dengjiayao
* @Last Modified time: 2017-07-12 09:25:59
*/

import Pages from '../../component/pages/pages.vue'
import { showMsg, getCastTalkUserLoginFail } from '../../vuex/action'

export default {
  name: 'cast-talk-feedback-list',
  components: {
    'vue-pages': Pages
  },
  data() {
    return {
      list: [],
      pages: {
        start: 0,
        totalPages: 0,
        limit: 20
      },
      search: {
        mobile: ''
      }
    }
  },
  vuex: {
    getters: {
      fresh: state => state.castTalkNeedFresh
    },
    actions: {
      xShowMsg: showMsg,
      xGetlist: getCastTalkUserLoginFail
    }
  },
  created() {
    this.getList({})
  },
  methods: {
    getList({mobile=this.search.mobile, start=this.pages.start, limit=this.pages.limit}) {
      var params = {
        start: start,
        limit: limit
      }
      if (mobile) {
        params.mobile = mobile
      }
      this.xGetlist(params)
        .then((res) => {
          this.list = res.data.list
          this.pages.totalPages = Math.ceil(res.data.count / this.pages.limit)
        })
        .catch((res) => {
          this.xShowMsg({
            type: 'danger',
            content: res.msg
          })
        })
    },
    searchUser() {
      this.getList({
        start: 0
      })
    }
  },
  watch: {
    fresh(val) {
      if (val) {
        this.getList({})
      }
    }
  }
}
